package com.yunji.order.dto.cmd;

import com.yunji.common.exception.ServiceException;
import com.yunji.order.domain.RefundDO;
import com.yunji.order.emuns.RefundStatusEnum;
import lombok.Data;

import java.util.Optional;

/**
 * @author : peter-zhu
 * @date : 2025/3/8 13:53
 * @description : TODO
 **/
@Data
public class RefundCommandDTO {
    private RefundDO refundDO;
    private RefundStatusEnum oldStatus;
    private RefundStatusEnum newStatus;

    public RefundCommandDTO() {
    }

    public RefundCommandDTO(RefundDO refundDO,RefundStatusEnum newStatus) {
        this.newStatus = newStatus;
        this.refundDO = refundDO;
    }

    public RefundStatusEnum getOldStatus() {
        Optional.ofNullable(refundDO).orElseThrow(() -> new ServiceException("退款单为null"));
        return RefundStatusEnum.fromCode(refundDO.getApplyStatus());
    }
}
